#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QtWidgets>
#include "mycombobox.h"
#include <QIcon>
#include <QSerialPort>
#include "myplaintextedit.h"
#include "recvthread.h"
#include "mytextedit.h"

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget* parent = nullptr);
    ~MainWindow();

private:
    void setupUi();
    MyComboBox* m_PortCombox;
    MyComboBox* m_BaudCombox;
    MyComboBox* m_DataCombox;
    MyComboBox* m_CheckCombox;
    MyComboBox* m_StopCombox;
    QPushButton* m_OpenButton;
    MyComboBox* m_SendFmtCombox;
    MyComboBox* m_ShowFmtCombox;
    QPushButton* m_ClearButton;
    QIcon m_OpenIcon;
    QIcon m_CloseIcon;
    QIcon m_ClearIcon;
    MyPlainTextEdit* m_textEdit;
    QComboBox* m_CmdComboBox;
    QPushButton* m_SendButton;
    QSerialPort m_serialPort;
    bool m_portOpened;
    bool m_showHex;
    bool m_sendHex;
    RecvThread m_recvThread;

private slots:
    void threadRecvReq(const QString &text);
    void sendFmtChange();
    void showFmtChange();
    void clearBtnClicked();
    void sendBtnClicked();
    void portComboxClicked(bool click);

private:
    void formatHex(QTextStream &str, const QByteArray &data);
    void openPort();
    void handleReadyRead();
    QByteArray HexStringToByteArray(QString HexString);
};
#endif // MAINWINDOW_H
